import java.util.Arrays;

public class Gloves {
    public static int findMinimum(int n, int[] left, int[] right) {
        // write code here
        if (n == 1) {
            return 2;
        }
        int leftCount = 0;
        int rightCount = 0;
        for (int i = 0; i < n; i++) {
            if (left[i] == 0) {
                rightCount += right[i];
                right[i] = 0;
                continue;
            }
            if (right[i] == 0) {
                leftCount += left[i];
                left[i] = 0;
                continue;
            }
        }
        Arrays.sort(left);
        Arrays.sort(right);
        for (int i = right.length-1; i >= 0; i--) {
            if (right[i] < left[i]) {
                if (right[i-1] == 0) {
                    break;
                }
                if (right[i] != 0) {
                    rightCount += right[i];
                }
            } else  {
                if (left[i-1] == 0) {
                    break;
                }
                if (left[i] != 0) {
                    leftCount += left[i];
                }
            }
        }
        rightCount += 1;
        leftCount += 1;
        return rightCount + leftCount;
    }

    public static void main(String[] args) {
        int[] l = {1,2,0,1,3,1};
        int[] r = {0,0,0,2,0,1};
        System.out.println(findMinimum(6, l, r));
    }
}